package com.ht.medicaltreatment.viewmodel

import androidx.lifecycle.viewModelScope
import com.blankj.utilcode.util.ToastUtils
import com.ht.medicaltreatment.bean.SampleRecordItemeBean
import com.xgst.lib.http.ApiResult
import kotlinx.coroutines.launch

class SampleRecordViewModel : BaseViewModel() {
    fun queryItem(map: MutableMap<String,String>,onSuccess:(MutableList<SampleRecordItemeBean>?)->Unit,onError:(String)->Unit){
        viewModelScope.launch {
            val bean = mApi.queryItem(map)
            when(bean){
                is ApiResult.Success -> onSuccess(bean.data.data)
                is ApiResult.Error -> onError(bean.errorMessage)
            }
        }
    }

    fun fangAn(onSuccess:(ArrayList<String>)->Unit){
        viewModelScope.launch {
            val bean = mApi.fangAn()
            when(bean){
                is ApiResult.Success -> {
                    val list = bean.data.data
                    val itemList = arrayListOf<String>()
                    list?.forEach {
                        itemList += it.protocolNumber
                    }
                    onSuccess(itemList)
                }
                is ApiResult.Error -> ToastUtils.showShort(bean.errorMessage)
            }
        }
    }
}
